﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ECONTACT.Controller;
using DevComponents.DotNetBar;

namespace ECONTACT
{
    public partial class frmPhuHuynh : Form
    {
        PhuHuynhCtrl m_PhuHuynhCtrl = new PhuHuynhCtrl();
        public frmPhuHuynh()
        {
            InitializeComponent();
        }

        private void frmPhuHuynh_Load(object sender, EventArgs e)
        {
            m_PhuHuynhCtrl.HienThi(dGVPhuHuynh, txtMaPhuHuynh, txtTenPhuHuynh, txtSoDienThoai, dtpNgaySinh, txtDiaChi);
            DataService.OpenConnection();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            //m_PhuHuynhCtrl.LuuPhuHuynh(txtMaPhuHuynh.Text, txtTenPhuHuynh.Text, txtSoDienThoai.Text, dtpNgaySinh.Value, txtDiaChi.Text);
            String rs = m_PhuHuynhCtrl.LuuPhuHuynh(txtTenPhuHuynh.Text, txtSoDienThoai.Text, dtpNgaySinh.Value, txtDiaChi.Text);
            if (!rs.Equals("Success"))
            {
                MessageBox.Show(rs);
            }
            m_PhuHuynhCtrl.HienThi(dGVPhuHuynh, txtMaPhuHuynh, txtTenPhuHuynh, txtSoDienThoai, dtpNgaySinh, txtDiaChi);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            String rs = m_PhuHuynhCtrl.UpdatePhuHuynh(txtMaPhuHuynh.Text, txtTenPhuHuynh.Text, txtSoDienThoai.Text, dtpNgaySinh.Value, txtDiaChi.Text);
            if (!rs.Equals("Success"))
            {
                MessageBox.Show(rs);
            }
            m_PhuHuynhCtrl.HienThi(dGVPhuHuynh, txtMaPhuHuynh, txtTenPhuHuynh, txtSoDienThoai, dtpNgaySinh, txtDiaChi);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (dGVPhuHuynh.RowCount == 0)
            {
                MessageBox.Show("Bạn chưa chọn dòng nào làm sao xóa!", "Thông báo");
            }
            else if (MessageBoxEx.Show("Bạn có chắc là xóa thiệt hok ?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                m_PhuHuynhCtrl.DeletePhuHuynh(txtMaPhuHuynh.Text);
                m_PhuHuynhCtrl.HienThi(dGVPhuHuynh, txtMaPhuHuynh, txtTenPhuHuynh, txtSoDienThoai, dtpNgaySinh, txtDiaChi);
            }

        }
    }
}
